<?php
/**
 * Created by PhpStorm.
 * User: fengbob
 * Date: 2018/5/7
 * Time: 11:43
 */

namespace app\controllers;


use app\librarys\Inteface;
use app\models\Institution;

class NotifyIntegralController extends Controller
{

    public function actionNotify(){
        $institution_code = $this->_getRequestValue('institution_code');
        $institution = Institution::getInstitutionByCode($institution_code);

        $cmd = \Yii::$app->db->createCommand('select last_user_integral_record_id from t_temp_notify_institution where id=1');
//        $cmd->bindValue(':in_goods_code', $goodsCode);
//        $cmd->bindValue(':in_quantity', $quantity);


        $last_user_integral_record_id = $cmd->queryScalar();

        $cmd = \Yii::$app->db->createCommand('select t1.id,t2.integral,t2.phone from t_user_integral_record t1 left join t_user t2 on t1.user_id = t2.id where t1.create_datetime > (select create_datetime from t_user_integral_record where id=:id) order by t1.create_datetime');
        $cmd->bindValue(':id', $last_user_integral_record_id);

        $data = $cmd->queryAll();

        foreach ($data as $a){
           $re = Inteface::sendIntegraltoCqChianLife($a['phone'],$a['integral']);
           $cmd1 = \Yii::$app->db->createCommand('update t_temp_notify_institution set last_user_integral_record_id=:id where id=1');
           $cmd1->bindValue(':id',$a['id']);
           $r = $cmd1->execute();
           echo($a['id'].' ok ' .$re);
        }
    }
}